package com.Service;

import com.domain.TblEmp;
import com.domain.TblEmpExample;
import com.domain.User;
import com.mapper.TblEmpMapper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class TblempService {
    @Autowired
    private TblEmpMapper tblEmpMapper;
    @Autowired
    private SqlSession sqlsession;

    public List<TblEmp> select() {
        List<TblEmp> testList = tblEmpMapper.selectByExample(null);
        return testList;
    }

    public List<TblEmp> selectdept() {
        List<TblEmp> testList = tblEmpMapper.selectwithDept(null);
        return testList;
    }

    public void batchinsert() {
        TblEmpMapper tblEmpMapper = sqlsession.getMapper(TblEmpMapper.class);
        for (int i = 0; i < 500; i++) {
            String uid = UUID.randomUUID().toString().substring(0, 5);
            tblEmpMapper.insert(new TblEmp(null, uid, "男", uid + "@qq.com", 1));
        }
    }

    public void deluser(int id) {

        tblEmpMapper.deleteByPrimaryKey(id);

    }

    public void adduser(TblEmp tblEmp) {
        tblEmpMapper.insert(tblEmp);
    }

    public TblEmp selbyid(int id){
        TblEmp tblEmp = tblEmpMapper.selectByPrimaryKey(id);
        return tblEmp;
    }
    public int updbyid(TblEmp tblEmp){
        return tblEmpMapper.updateByPrimaryKey(tblEmp);
    }
    public void delbatch(List<Integer> ids){
        TblEmpExample example = new TblEmpExample();
        example.createCriteria().andEmpIdIn(ids);
        tblEmpMapper.deleteByExample(example);
    }
}
